package com.zzu.presenter.impl;

import android.content.Context;

import com.zzu.model.bean.PackageDetail;
import com.zzu.model.bean.PackageRoute;
import com.zzu.model.bean.PackageRouteDetail;
import com.zzu.model.impl.PackageModelImpl;
import com.zzu.model.service.PackageRouteService;
import com.zzu.model.service.PackageService;
import com.zzu.utils.ServiceCreator;
import com.zzu.utils.ToastAndDialogUtils;
import com.zzu.view.view.PackageQueryView;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @ClassName PackageRoutePresenterImpl
 * @Description TODO
 * @Author ZB
 * @Date 2021/5/22 17:40
 * @Version 1.0
 **/
public class PackageRoutePresenterImpl {

    private static final String TAG = PackagePresenterImpl.class.getName();

    private PackageRouteService packageRouteService = ServiceCreator.getRetrofit(PackageRouteService.class);

    PackageQueryView mPackageQueryView = null;
    Context context = null;
    public PackageRoutePresenterImpl(Context context, PackageQueryView packageQueryView){
        this.context = context;
        mPackageQueryView = packageQueryView;
    }

    /**
     * 通过运单号得到包裹的路径
     */
    public void getPackageRouteDetailByPackageId(String packageId){
        Call<List<PackageRouteDetail>> call = packageRouteService.getPackageRouteDetailByPackageId(packageId);
        call.enqueue(new Callback<List<PackageRouteDetail>>() {
            @Override
            public void onResponse(Call<List<PackageRouteDetail>> call, Response<List<PackageRouteDetail>> response) {
                if(mPackageQueryView != null){
                    List<PackageRouteDetail> datas = response.body();
                    mPackageQueryView.getDates(datas);
                }
            }

            @Override
            public void onFailure(Call<List<PackageRouteDetail>> call, Throwable t) {
                ToastAndDialogUtils.showShort(context,"请求服务器失败"+t);
            }
        });
    }

}
